package com.kfm.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet(urlPatterns = {"/hello", "/a"}, initParams = {@WebInitParam(name="age", value="20"), @WebInitParam(name="addr", value="西安")})
public class HelloServlet implements Servlet {

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("HelloServlet --> init()");
        System.out.println(config.getServletContext());
        System.out.println(config.getServletName());

        Enumeration<String> initParameterNames = config.getInitParameterNames();

        while(initParameterNames.hasMoreElements()){
            String name = initParameterNames.nextElement();

            String value = config.getInitParameter(name);

            System.out.println(name + " = " + value);
        }
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        System.out.println("HelloServlet --> service()");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("HelloServlet --> destroy()");
    }
}
